package com.cuitrip.business.reminder;

import android.app.Activity;
import android.os.Bundle;

import com.cuitrip.business.login.LoginInstance;
import com.cuitrip.business.reminder.model.ConfirmFailViewHolder;
import com.cuitrip.business.reminder.model.ConfirmSuccessViewHolder;
import com.cuitrip.business.reminder.model.FinderReceiveModifyOrderViewHolder;
import com.cuitrip.business.reminder.model.FinderReceiveOrderViewHolder;
import com.cuitrip.business.reminder.model.OrderCancelViewHolder;
import com.cuitrip.business.reminder.model.PaySuccessViewHolder;
import com.cuitrip.business.reminder.model.ReminderViewHolder;
import com.cuitrip.business.reminder.model.StartingReminderViewHolder;
import com.cuitrip.business.reminder.model.TripCommentViewHolder;
import com.cuitrip.business.reminder.model.TripEndViewHolder;
import com.cuitrip.business.user.model.CtUserInfo;
import com.cuitrip.push.model.PushMessageModel;
import com.cuitrip.push.model.TypeKeyMap;

/**
 * 行程状态提醒dialog
 * Created by ak
 */
public class RemindDialogActivity extends Activity {


    public static final String DATA_KEY = "data";

    public static final String TYPE_KEY = "type";
    ReminderViewHolder reminderViewHolder;

    private PushMessageModel pushMessageModel;
    private boolean statusChange;


    private void bindViewHolder(int type) {
        if (type == -1) {
            finish();
        }

        switch (type) {
            case TypeKeyMap.kConfirmOrderMsg:
                reminderViewHolder = new ConfirmSuccessViewHolder();
                break;
            case TypeKeyMap.kRefuseOrderMsg:
                reminderViewHolder = new ConfirmFailViewHolder();
                break;
            case TypeKeyMap.kPaidOrderMsg:
                reminderViewHolder = new PaySuccessViewHolder();
                break;
            case TypeKeyMap.kEndOrderMsg:
                reminderViewHolder = new TripEndViewHolder();
                break;
            case TypeKeyMap.kBeginOrderMsg:
                reminderViewHolder = new StartingReminderViewHolder();
                break;
            case TypeKeyMap.kBuyOrderMsg:
                reminderViewHolder = new FinderReceiveOrderViewHolder();
                break;
            case TypeKeyMap.kCancelOrderMsg:
                reminderViewHolder = new OrderCancelViewHolder();
                break;
            case TypeKeyMap.kCommentMsg:
                reminderViewHolder = new TripCommentViewHolder();
                break;
            case TypeKeyMap.kModifyOrderMsg:
                reminderViewHolder = new FinderReceiveModifyOrderViewHolder();
                break;
        }

    }

    private boolean needChangeType = false;

    public void setNeedChangeType(boolean needChangeType){
        this.needChangeType = needChangeType;
    }

    public boolean isNeedChangeType() {
        return needChangeType;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getIntent().hasExtra(DATA_KEY)) {
            pushMessageModel = (PushMessageModel) getIntent().getSerializableExtra(DATA_KEY);
        } else {
            finish();
        }

        final CtUserInfo userInfo = LoginInstance.getInstance().getUserInfo();
        boolean isTravel = (pushMessageModel.getUserType() == PushMessageModel.TRAVELLER);
        if(userInfo!=null){
            statusChange = userInfo.isTravel() != isTravel;

        }
        setNeedChangeType(statusChange);


        bindViewHolder(pushMessageModel.getMessageType());
        setContentView(reminderViewHolder.withLayoutRes());
        reminderViewHolder.build(this);
        reminderViewHolder.render(pushMessageModel);

    }


}
